﻿#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QFileInfoList>
#include <QTextStream>
#include <QImage>


//转换png图片，去除srgb警告

void checkPath(QString path)
{
    QDir dir(path);

    QStringList nameFilters;
    nameFilters<<"*.png";
    QFileInfoList list = dir.entryInfoList(nameFilters, QDir::AllEntries | QDir::AllDirs |  QDir::NoDotAndDotDot, QDir::NoSort);

    foreach (QFileInfo info, list) {

        qDebug()<<info.absolutePath()<<info.fileName()<<info.filePath();

        if(info.isDir()){
            //遍历
            checkPath(info.filePath());
        }
        else{
//            qDebug()<<info.filePath();
            QImage image(info.filePath());
            QFile file(info.filePath());
            if(file.exists())
            {
                file.remove();
            }
            file.close();
            bool b = image.save(info.filePath());
            qDebug()<<info.filePath()<<b;
        }
    }
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QDir::setCurrent(a.applicationDirPath());
    qDebug()<<"start"<<QDir::currentPath();

    if(argc >= 2)
    {
//        flag = QString(argv[1]);
    }
    else{
//        flag = "1";
    }

    QString needPath = "F:\\projects\\svnHMI\\SOC\\EJANUS2\\hmi";

    checkPath(needPath);

    exit(0);

    return a.exec();
}
